package com.py.credit.service.impl;

import com.py.credit.dao.CheckReportDao;
import com.py.credit.entity.Application;
import com.py.credit.entity.CheckReport;
import com.py.credit.service.CheckReportService;
import com.py.credit.utils.SQLBuilder;
import com.py.framework.core.common.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CheckReportServiceImpl implements CheckReportService {

	@Autowired
	private CheckReportDao checkReportDao;

	@Override
	public int addApplicationInfo(String applicant_unit, String tybm, String check_purpose, String applicat_date, int user_id,String username) {
		Application application = new Application();
		application.setApplicant_unit(applicant_unit);
		application.setTybm(tybm);
		application.setCheck_purpose(check_purpose);
		application.setApplicat_date(applicat_date);
		application.setUser_id(user_id);
		application.setUsername(username);
		checkReportDao.addApplicationInfo(application);
		return application.getId();
	}

	@Override
	public Application selectApplicationInfo(int id) {
		return checkReportDao.selectApplicationInfo(id);
	}
	
	@Override
	public CheckReport selectCheckReportInfo(int id) {
		return checkReportDao.selectCheckReportInfo(id);
	}

	@Override
	public String selectTybmByQymc(String qymc) {
		return checkReportDao.selectTybmByQymc(qymc);
	}

	@Override
	public void updateApplication(int id, String managerDate, String status, String pdfpath) {
		checkReportDao.updateApplication(id, managerDate, status, pdfpath);
	}

	@Override
	public List<Application> selectApplicationInfoList(int userId) {
		return checkReportDao.selectApplicationInfoList(userId);
	}

	@Override
	public int addCheck(String ztmc, String tyshxydm,String tybm, String fddbr, String lxr, String lxrdh, String yx, String bz,String purpose,String purpose_str,
			Integer userId,String username) {
		CheckReport checkReport=new CheckReport();
		checkReport.setPurpose(purpose);
		checkReport.setPurpose_str(purpose_str);
		checkReport.setTyshxydm(tyshxydm);
		checkReport.setTybm(tybm);
		checkReport.setFddbr(fddbr);
		checkReport.setLxr(lxr);
		checkReport.setLxrdh(lxrdh);
		checkReport.setYx(yx);
		checkReport.setBz(bz);
		checkReport.setZtmc(ztmc);
		checkReport.setUserId(userId);
		checkReport.setUsername(username);
	    checkReportDao.addCheck(checkReport);
	    return checkReport.getId();
	}

	@Override
	public void updateCheckReport(int id, String checkTime, String checkStatus, String pdfpath) {
		checkReportDao.updateCheckReport(id, checkTime, checkStatus, pdfpath);
		
	}

	@Override
	public List<CheckReport> selectCheckReportInfoList(int userId) {
		// TODO Auto-generated method stub
		return checkReportDao.selectCheckReportInfoList(userId);
	}
	
	@Override
	public List<CheckReport> getByConditionForPage(List<String> columns, String[] additionalColumns,
			String conditionStr, Page page,String checkStatus,String addTimeStart,String addTimeEnd, int userId) {
		List<String> conditions = SQLBuilder.createConditionSql(conditionStr);
		List<CheckReport> batchLogs = checkReportDao.selectByConditionForPage(columns, additionalColumns,
				conditions, page, checkStatus,addTimeStart,addTimeEnd, userId);

		return batchLogs;
	}

	@Override
	public Map selectUserInfo(Integer id) {
		// TODO Auto-generated method stub
		return checkReportDao.selectUserInfo(id);
	}

	@Override
	public Map selectUserInfoByUserId(Integer userId) {
		// TODO Auto-generated method stub
		return checkReportDao.selectUserInfoByUserId(userId);
	}
}
